# Updated 2012/11/20 by Wei
# This program is written for generating positional features for the individual postings
# Let's do the complex positional features, man.
from __future__ import division
import os
import sys

def computeComplexFeaturesSupportedData(doc_words,queryVariationID,queryVariationString,outputFileHandlerForTf_dict,cf_dict_in_function,df_dict_in_function,trecID):
    # print doc_words
    
    # print "    ---> Processing:",queryVariationID,queryVariationString
    indicesList = []
    queryVariationList = queryVariationString.split("_")
    for queryTerm in queryVariationList:
        currentIndices = [i for i, x in enumerate(doc_words) if x == queryTerm]
        indicesList.append(currentIndices)
    
    #print "raw indices"

    
    M_Constant_32 = 32
    M_Constant_8 = 8
    M_Constant_4 = 4
    M_Constant_1 = 1
    
    N_Constant_32 = 32
    N_Constant_8 = 8
    N_Constant_4 = 4
    N_Constant_1 = 1
    
    tf_M_1 = 0
    tf_M_4 = 0
    tf_M_8 = 0
    tf_M_32 = 0
    
    tf_N_ordered_1 = 0
    tf_N_ordered_4 = 0
    tf_N_ordered_8 = 0
    tf_N_ordered_32 = 0

    tf_N_unordered_1 = 0
    tf_N_unordered_4 = 0
    tf_N_unordered_8 = 0
    tf_N_unordered_32 = 0    
    
    
    # Let's do the M computation
    # need to assign the head indices
    # a dict structure for final judge
    tempImportantPositionsList_M32 = []
    tempImportantPositionsList_M8 = []
    tempImportantPositionsList_M4 = []
    tempImportantPositionsList_M1 = []
    
    indicesConditionDict_M32 = {}
    indicesConditionDict_M8 = {}
    indicesConditionDict_M4 = {}
    indicesConditionDict_M1 = {}
    
    for i in range(0,len(indicesList)):
        indicesConditionDict_M32[i] = False
        indicesConditionDict_M8[i] = False
        indicesConditionDict_M4[i] = False
        indicesConditionDict_M1[i] = False
    # print "old indicesConditionDict_M32:",indicesConditionDict_M32
    # set the head indices to be True
    indicesConditionDict_M32[0] = True
    indicesConditionDict_M8[0] = True
    indicesConditionDict_M4[0] = True
    indicesConditionDict_M1[0] = True
    
    # assignment loop
    for indexNumberFromIndex1 in indicesList[0]:
        
        tempImportantPositionsList_M32.append( (indexNumberFromIndex1,0) )
        tempImportantPositionsList_M8.append( (indexNumberFromIndex1,0) )
        tempImportantPositionsList_M4.append( (indexNumberFromIndex1,0) )
        tempImportantPositionsList_M1.append( (indexNumberFromIndex1,0) )
        
        for index,currentIndices in enumerate(indicesList[1:]):
            # for the other indices
            for currentIndicesPositionNumber in currentIndices:
                # core judge statements
                if currentIndicesPositionNumber >= indexNumberFromIndex1 and currentIndicesPositionNumber <= indexNumberFromIndex1 + M_Constant_1 + 1:
                    indicesConditionDict_M1[index+1] = True
                    tempImportantPositionsList_M1.append( (currentIndicesPositionNumber,index+1) )
                
                if currentIndicesPositionNumber >= indexNumberFromIndex1 and currentIndicesPositionNumber <= indexNumberFromIndex1 + M_Constant_4 + 1:
                    indicesConditionDict_M4[index+1] = True
                    tempImportantPositionsList_M4.append( (currentIndicesPositionNumber,index+1) )
                
                if currentIndicesPositionNumber >= indexNumberFromIndex1 and currentIndicesPositionNumber <= indexNumberFromIndex1 + M_Constant_8 + 1:
                    indicesConditionDict_M8[index+1] = True
                    tempImportantPositionsList_M8.append( (currentIndicesPositionNumber,index+1) )
                
                if currentIndicesPositionNumber >= indexNumberFromIndex1 and currentIndicesPositionNumber <= indexNumberFromIndex1 + M_Constant_32 + 1:
                    indicesConditionDict_M32[index+1] = True
                    tempImportantPositionsList_M32.append( (currentIndicesPositionNumber,index+1) )
                    break
              
        # judge loop
        allConditionSafisfiedFlag_M32 = True
        allConditionSafisfiedFlag_M8 = True
        allConditionSafisfiedFlag_M4 = True
        allConditionSafisfiedFlag_M1 = True
        

        for i in indicesConditionDict_M32:
            if indicesConditionDict_M32[i] == False:
                allConditionSafisfiedFlag_M32 =False

        for i in indicesConditionDict_M8:
            if indicesConditionDict_M8[i] == False:
                allConditionSafisfiedFlag_M8 =False

        for i in indicesConditionDict_M4:
            if indicesConditionDict_M4[i] == False:
                allConditionSafisfiedFlag_M4 =False

        for i in indicesConditionDict_M1:
            if indicesConditionDict_M1[i] == False:
                allConditionSafisfiedFlag_M1 =False


        if allConditionSafisfiedFlag_M32:
            #print 
            #print indicesConditionDict_M32
            #print tempImportantPositionsList_M32
            
            minPosition = 999999
            maxPosition = 0
            outputLine = ""
            for currentTuple in tempImportantPositionsList_M32:
                (currentPosition,_) = currentTuple
                
                outputLine += doc_words[currentPosition] + " "
                
                if currentPosition < minPosition:
                    minPosition = currentPosition
                
                if currentPosition > maxPosition:
                    maxPosition = currentPosition
            #print "minPosition:",minPosition
            #print "maxPosition:",maxPosition
            #print outputLine
            #print doc_words[minPosition:maxPosition+1]
            tf_M_32 += 1

        if allConditionSafisfiedFlag_M8:
            #print 
            #print indicesConditionDict_M8
            #print tempImportantPositionsList_M8
            
            minPosition = 999999
            maxPosition = 0
            outputLine = ""
            for currentTuple in tempImportantPositionsList_M8:
                (currentPosition,_) = currentTuple
                
                outputLine += doc_words[currentPosition] + " "
                
                if currentPosition < minPosition:
                    minPosition = currentPosition
                
                if currentPosition > maxPosition:
                    maxPosition = currentPosition
            #print "minPosition:",minPosition
            #print "maxPosition:",maxPosition
            #print outputLine
            #print doc_words[minPosition:maxPosition+1]
            tf_M_8 += 1

        if allConditionSafisfiedFlag_M4:
            #print 
            #print indicesConditionDict_M4
            #print tempImportantPositionsList_M4
            
            minPosition = 999999
            maxPosition = 0
            outputLine = ""
            for currentTuple in tempImportantPositionsList_M4:
                (currentPosition,_) = currentTuple
                
                outputLine += doc_words[currentPosition] + " "
                
                if currentPosition < minPosition:
                    minPosition = currentPosition
                
                if currentPosition > maxPosition:
                    maxPosition = currentPosition
            #print "minPosition:",minPosition
            #print "maxPosition:",maxPosition
            #print outputLine
            #print doc_words[minPosition:maxPosition+1]
            tf_M_4 += 1
        
        # for M1
        if allConditionSafisfiedFlag_M1:
            #print 
            #print indicesConditionDict_M1
            #print tempImportantPositionsList_M1
            
            minPosition = 999999
            maxPosition = 0
            outputLine = ""
            for currentTuple in tempImportantPositionsList_M1:
                (currentPosition,_) = currentTuple
                
                outputLine += doc_words[currentPosition] + " "
                
                if currentPosition < minPosition:
                    minPosition = currentPosition
                
                if currentPosition > maxPosition:
                    maxPosition = currentPosition
            #print "minPosition:",minPosition
            #print "maxPosition:",maxPosition
            #print outputLine
            #print doc_words[minPosition:maxPosition+1]
            tf_M_1 += 1            
            
                     
        # reset the judge dict
        for i in range(0,len(indicesList)):
            indicesConditionDict_M32[i] = False
        indicesConditionDict_M32[0] = True
        del tempImportantPositionsList_M32[:]
        
        # reset the judge dict
        for i in range(0,len(indicesList)):
            indicesConditionDict_M8[i] = False
        indicesConditionDict_M8[0] = True
        del tempImportantPositionsList_M8[:]
        
        # reset the judge dict
        for i in range(0,len(indicesList)):
            indicesConditionDict_M4[i] = False
        indicesConditionDict_M4[0] = True
        del tempImportantPositionsList_M4[:]
        
        # reset the judge dict
        for i in range(0,len(indicesList)):
            indicesConditionDict_M1[i] = False
        indicesConditionDict_M1[0] = True
        del tempImportantPositionsList_M1[:]
        
#######################################################N computation NEW version begins...
    # Let's do the N computation (teh ordered part)
    # need to assign the head indices
    # a dict structure for final judge
    
    tempImportantPositionsList_N32_ordered = []
    tempImportantPositionsList_N8_ordered = []
    tempImportantPositionsList_N4_ordered = []
    tempImportantPositionsList_N1_ordered = []
    
    indicesConditionDict_N32_ordered = {}
    indicesConditionDict_N8_ordered = {}
    indicesConditionDict_N4_ordered = {}
    indicesConditionDict_N1_ordered = {}
    
    for i in range(0,len(indicesList)):
        indicesConditionDict_N32_ordered[i] = False
        indicesConditionDict_N8_ordered[i] = False
        indicesConditionDict_N4_ordered[i] = False
        indicesConditionDict_N1_ordered[i] = False
    
    
    # set the head indices to be True
    indicesConditionDict_N32_ordered[0] = True
    indicesConditionDict_N8_ordered[0] = True
    indicesConditionDict_N4_ordered[0] = True
    indicesConditionDict_N1_ordered[0] = True
    
    # assignment loop
    for indexNumberFromIndex1 in indicesList[0]:
        
        tempImportantPositionsList_N32_ordered.append( (indexNumberFromIndex1,0) )
        tempImportantPositionsList_N8_ordered.append( (indexNumberFromIndex1,0) )
        tempImportantPositionsList_N4_ordered.append( (indexNumberFromIndex1,0) )
        tempImportantPositionsList_N1_ordered.append( (indexNumberFromIndex1,0) )
        
        for index,currentIndices in enumerate(indicesList[1:]):
            # for the other indices
            for currentIndicesPositionNumber in currentIndices:
                # core judge statements
                if currentIndicesPositionNumber >= indexNumberFromIndex1 and currentIndicesPositionNumber <= indexNumberFromIndex1 + N_Constant_1 - 1:
                    indicesConditionDict_N1_ordered[index+1] = True
                    tempImportantPositionsList_N1_ordered.append( (currentIndicesPositionNumber,index+1) )
                
                if currentIndicesPositionNumber >= indexNumberFromIndex1 and currentIndicesPositionNumber <= indexNumberFromIndex1 + N_Constant_4 - 1:
                    indicesConditionDict_N4_ordered[index+1] = True
                    tempImportantPositionsList_N4_ordered.append( (currentIndicesPositionNumber,index+1) )
                
                if currentIndicesPositionNumber >= indexNumberFromIndex1 and currentIndicesPositionNumber <= indexNumberFromIndex1 + N_Constant_8 - 1:
                    indicesConditionDict_N8_ordered[index+1] = True
                    tempImportantPositionsList_N8_ordered.append( (currentIndicesPositionNumber,index+1) )
                
                if currentIndicesPositionNumber >= indexNumberFromIndex1 and currentIndicesPositionNumber <= indexNumberFromIndex1 + N_Constant_32 - 1:
                    indicesConditionDict_N32_ordered[index+1] = True
                    tempImportantPositionsList_N32_ordered.append( (currentIndicesPositionNumber,index+1) )
                    break
              
        # judge loop
        allConditionSafisfiedFlag_N32_ordered = True
        allConditionSafisfiedFlag_N8_ordered = True
        allConditionSafisfiedFlag_N4_ordered = True
        allConditionSafisfiedFlag_N1_ordered = True
        

        for i in indicesConditionDict_N32_ordered:
            if indicesConditionDict_N32_ordered[i] == False:
                allConditionSafisfiedFlag_N32_ordered =False

        for i in indicesConditionDict_N8_ordered:
            if indicesConditionDict_N8_ordered[i] == False:
                allConditionSafisfiedFlag_N8_ordered =False

        for i in indicesConditionDict_N4_ordered:
            if indicesConditionDict_N4_ordered[i] == False:
                allConditionSafisfiedFlag_N4_ordered =False

        for i in indicesConditionDict_N1_ordered:
            if indicesConditionDict_N1_ordered[i] == False:
                allConditionSafisfiedFlag_N1_ordered =False

        # for N32_ordered
        if allConditionSafisfiedFlag_N32_ordered:
            #print 
            #print "in N32_ordered"
            #print indicesConditionDict_N32_ordered
            #print tempImportantPositionsList_N32_ordered
            
            minPosition = 999999
            maxPosition = 0
            outputLine = ""
            for currentTuple in tempImportantPositionsList_N32_ordered:
                (currentPosition,_) = currentTuple
                
                outputLine += doc_words[currentPosition] + " "
                
                if currentPosition < minPosition:
                    minPosition = currentPosition
                
                if currentPosition > maxPosition:
                    maxPosition = currentPosition
            #print "minPosition:",minPosition
            #print "maxPosition:",maxPosition
            #print outputLine
            #print doc_words[minPosition:maxPosition+1]
            tf_N_ordered_32 += 1
            
        # for N8_ordered
        if allConditionSafisfiedFlag_N8_ordered:
            #print 
            #print "in N8_ordered"
            #print indicesConditionDict_N8_ordered
            #print tempImportantPositionsList_N8_ordered
            
            minPosition = 999999
            maxPosition = 0
            outputLine = ""
            for currentTuple in tempImportantPositionsList_N8_ordered:
                (currentPosition,_) = currentTuple
                
                outputLine += doc_words[currentPosition] + " "
                
                if currentPosition < minPosition:
                    minPosition = currentPosition
                
                if currentPosition > maxPosition:
                    maxPosition = currentPosition
            #print "minPosition:",minPosition
            #print "maxPosition:",maxPosition
            #print outputLine
            #print doc_words[minPosition:maxPosition+1]
            tf_N_ordered_8 += 1
            
        # for N4_ordered
        if allConditionSafisfiedFlag_N4_ordered:
            #print 
            #print "in N4_ordered"
            #print indicesConditionDict_N4_ordered
            #print tempImportantPositionsList_N4_ordered
            
            minPosition = 999999
            maxPosition = 0
            outputLine = ""
            for currentTuple in tempImportantPositionsList_N4_ordered:
                (currentPosition,_) = currentTuple
                
                outputLine += doc_words[currentPosition] + " "
                
                if currentPosition < minPosition:
                    minPosition = currentPosition
                
                if currentPosition > maxPosition:
                    maxPosition = currentPosition
            #print "minPosition:",minPosition
            #print "maxPosition:",maxPosition
            #print outputLine
            #print doc_words[minPosition:maxPosition+1]
            tf_N_ordered_4 += 1
        
        # for N1_ordered
        if allConditionSafisfiedFlag_N1_ordered:
            #print 
            #print "in N1_ordered"
            #print indicesConditionDict_N1_ordered
            #print tempImportantPositionsList_N1_ordered
            
            minPosition = 999999
            maxPosition = 0
            outputLine = ""
            for currentTuple in tempImportantPositionsList_N1_ordered:
                (currentPosition,_) = currentTuple
                
                outputLine += doc_words[currentPosition] + " "
                
                if currentPosition < minPosition:
                    minPosition = currentPosition
                
                if currentPosition > maxPosition:
                    maxPosition = currentPosition
            #print "minPosition:",minPosition
            #print "maxPosition:",maxPosition
            #print outputLine
            #print doc_words[minPosition:maxPosition+1]
            tf_N_ordered_1 += 1            
            
                     
        # reset the judge dict
        for i in range(0,len(indicesList)):
            indicesConditionDict_N32_ordered[i] = False
        indicesConditionDict_N32_ordered[0] = True
        del tempImportantPositionsList_N32_ordered[:]
        
        # reset the judge dict
        for i in range(0,len(indicesList)):
            indicesConditionDict_N8_ordered[i] = False
        indicesConditionDict_N8_ordered[0] = True
        del tempImportantPositionsList_N8_ordered[:]
        
        # reset the judge dict
        for i in range(0,len(indicesList)):
            indicesConditionDict_N4_ordered[i] = False
        indicesConditionDict_N4_ordered[0] = True
        del tempImportantPositionsList_N4_ordered[:]
        
        # reset the judge dict
        for i in range(0,len(indicesList)):
            indicesConditionDict_N1_ordered[i] = False
        indicesConditionDict_N1_ordered[0] = True
        del tempImportantPositionsList_N1_ordered[:]
#######################################################N computation NEW version ends.

#######################################################N computation(unordered part) NEW version begins...
    # Let's do the N computation (unordered part)
    # need to assign the head indices
    # a dict structure for final judge
    
    tempImportantPositionsList_N32_unordered = []
    tempImportantPositionsList_N8_unordered = []
    tempImportantPositionsList_N4_unordered = []
    tempImportantPositionsList_N1_unordered = []
    
    indicesConditionDict_N32_unordered = {}
    indicesConditionDict_N8_unordered = {}
    indicesConditionDict_N4_unordered = {}
    indicesConditionDict_N1_unordered = {}
    
    for i in range(0,len(indicesList)):
        indicesConditionDict_N32_unordered[i] = False
        indicesConditionDict_N8_unordered[i] = False
        indicesConditionDict_N4_unordered[i] = False
        indicesConditionDict_N1_unordered[i] = False
    
    
    # set the head indices to be True
    indicesConditionDict_N32_unordered[0] = True
    indicesConditionDict_N8_unordered[0] = True
    indicesConditionDict_N4_unordered[0] = True
    indicesConditionDict_N1_unordered[0] = True
    
    # assignment loop
    # print "len(head word):",len(indicesList[0])
    for indexNumberFromIndex1 in indicesList[0]:
        
        tempImportantPositionsList_N32_unordered.append( (indexNumberFromIndex1,0) )
        tempImportantPositionsList_N8_unordered.append( (indexNumberFromIndex1,0) )
        tempImportantPositionsList_N4_unordered.append( (indexNumberFromIndex1,0) )
        tempImportantPositionsList_N1_unordered.append( (indexNumberFromIndex1,0) )
        
        # grab from other indices
        for index,currentIndices in enumerate(indicesList[1:]):
            
            
            # for that word and for that window
            foundFlagForSpecifcWindowSize1 = False
            foundFlagForSpecifcWindowSize2 = False
            foundFlagForSpecifcWindowSize3 = False
            foundFlagForSpecifcWindowSize4 = False
            
            # for that word currentIndices
            for currentIndicesPositionNumber in currentIndices:
                # new version
                # The consideration range is: 
                # for window size = 1
                # consideration range
                # indexNumberFromIndex1
                # for window size = 4
                # consideration range
                # indexNumberFromIndex1 - 3 : indexNumberFromIndex1 + 3
                # for window size = 8
                # consideration range
                # indexNumberFromIndex1 - 7 : indexNumberFromIndex1 + 7
                # for window size = 32
                # consideration range
                # indexNumberFromIndex1 - 31 : indexNumberFromIndex1 + 31
                
                
                # for window size = 1
                if not foundFlagForSpecifcWindowSize1:
                    for i in range( indexNumberFromIndex1,indexNumberFromIndex1):
                        if currentIndicesPositionNumber >= i and currentIndicesPositionNumber <= i + N_Constant_1 - 1:
                            indicesConditionDict_N1_unordered[index+1] = True
                            tempImportantPositionsList_N1_unordered.append( (currentIndicesPositionNumber,index+1) ) 
                            foundFlagForSpecifcWindowSize1 = True
                            break

                # for window size = 4
                if not foundFlagForSpecifcWindowSize2:
                    for i in range( indexNumberFromIndex1 - N_Constant_4 + 1,indexNumberFromIndex1):
                        if currentIndicesPositionNumber >= i and currentIndicesPositionNumber <= i + N_Constant_4 - 1:
                            indicesConditionDict_N4_unordered[index+1] = True
                            tempImportantPositionsList_N4_unordered.append( (currentIndicesPositionNumber,index+1) )                    
                            foundFlagForSpecifcWindowSize2 = True
                            break

                # for window size = 8
                if not foundFlagForSpecifcWindowSize3:
                    for i in range( indexNumberFromIndex1 - N_Constant_8 + 1,indexNumberFromIndex1):
                        if currentIndicesPositionNumber >= i and currentIndicesPositionNumber <= i + N_Constant_8 - 1:
                            indicesConditionDict_N8_unordered[index+1] = True
                            tempImportantPositionsList_N8_unordered.append( (currentIndicesPositionNumber,index+1) )                    
                            foundFlagForSpecifcWindowSize3 = True
                            break

                # for window size = 32
                if not foundFlagForSpecifcWindowSize4:
                    for i in range( indexNumberFromIndex1 - N_Constant_32 + 1,indexNumberFromIndex1):
                        if currentIndicesPositionNumber >= i and currentIndicesPositionNumber <= i + N_Constant_32 - 1:
                            indicesConditionDict_N32_unordered[index+1] = True
                            #print "append:",indexNumberFromIndex1,i,currentIndicesPositionNumber,index+1
                            tempImportantPositionsList_N32_unordered.append( (currentIndicesPositionNumber,index+1) )                    
                            foundFlagForSpecifcWindowSize4 = True
                            break
                                                
                
                '''
                # old version
                # core judge statements
                if currentIndicesPositionNumber >= indexNumberFromIndex1 and currentIndicesPositionNumber <= indexNumberFromIndex1 + N_Constant_1 - 1:
                    indicesConditionDict_N1_unordered[index+1] = True
                    tempImportantPositionsList_N1_unordered.append( (currentIndicesPositionNumber,index+1) )
                
                if currentIndicesPositionNumber >= indexNumberFromIndex1 and currentIndicesPositionNumber <= indexNumberFromIndex1 + N_Constant_4 - 1:
                    indicesConditionDict_N4_unordered[index+1] = True
                    tempImportantPositionsList_N4_unordered.append( (currentIndicesPositionNumber,index+1) )
                
                if currentIndicesPositionNumber >= indexNumberFromIndex1 and currentIndicesPositionNumber <= indexNumberFromIndex1 + N_Constant_8 - 1:
                    indicesConditionDict_N8_unordered[index+1] = True
                    tempImportantPositionsList_N8_unordered.append( (currentIndicesPositionNumber,index+1) )
                
                if currentIndicesPositionNumber >= indexNumberFromIndex1 and currentIndicesPositionNumber <= indexNumberFromIndex1 + N_Constant_32 - 1:
                    indicesConditionDict_N32_unordered[index+1] = True
                    tempImportantPositionsList_N32_unordered.append( (currentIndicesPositionNumber,index+1) )
                    break
                '''

            # for that word and for that window
            foundFlagForSpecifcWindowSize1 = True
            foundFlagForSpecifcWindowSize2 = True
            foundFlagForSpecifcWindowSize3 = True
            foundFlagForSpecifcWindowSize4 = True
                
        # judge loop
        allConditionSafisfiedFlag_N32_unordered = True
        allConditionSafisfiedFlag_N8_unordered = True
        allConditionSafisfiedFlag_N4_unordered = True
        allConditionSafisfiedFlag_N1_unordered = True
        

        for i in indicesConditionDict_N32_unordered:
            if indicesConditionDict_N32_unordered[i] == False:
                allConditionSafisfiedFlag_N32_unordered =False

        for i in indicesConditionDict_N8_unordered:
            if indicesConditionDict_N8_unordered[i] == False:
                allConditionSafisfiedFlag_N8_unordered =False

        for i in indicesConditionDict_N4_unordered:
            if indicesConditionDict_N4_unordered[i] == False:
                allConditionSafisfiedFlag_N4_unordered =False

        for i in indicesConditionDict_N1_unordered:
            if indicesConditionDict_N1_unordered[i] == False:
                allConditionSafisfiedFlag_N1_unordered =False

        # for N32_ordered
        if allConditionSafisfiedFlag_N32_unordered:
            #print 
            #print "in N32_unordered"
            #print indicesConditionDict_N32_unordered
            #print tempImportantPositionsList_N32_unordered
            
            minPosition = 999999
            maxPosition = 0
            outputLine = ""
            tempImportantPositionsList_N32_unordered.sort(cmp=None, key=None, reverse=False)
            #print tempImportantPositionsList_N32_unordered
            for currentTuple in tempImportantPositionsList_N32_unordered:
                (currentPosition,_) = currentTuple
                
                outputLine += doc_words[currentPosition] + " "
                
                if currentPosition < minPosition:
                    minPosition = currentPosition
                
                if currentPosition > maxPosition:
                    maxPosition = currentPosition
            #print "minPosition:",minPosition
            #print "maxPosition:",maxPosition
            #print outputLine
            #print doc_words[minPosition:maxPosition+1]
            tf_N_unordered_32 += 1
            
        # for N8_ordered
        if allConditionSafisfiedFlag_N8_unordered:
            #print 
            #print "in N8_unordered"
            #print indicesConditionDict_N8_unordered
            #print tempImportantPositionsList_N8_unordered
            
            minPosition = 999999
            maxPosition = 0
            outputLine = ""
            
            tempImportantPositionsList_N8_unordered.sort(cmp=None, key=None, reverse=False)
            #print tempImportantPositionsList_N8_unordered
            for currentTuple in tempImportantPositionsList_N8_unordered:
                (currentPosition,_) = currentTuple
                
                outputLine += doc_words[currentPosition] + " "
                
                if currentPosition < minPosition:
                    minPosition = currentPosition
                
                if currentPosition > maxPosition:
                    maxPosition = currentPosition
            #print "minPosition:",minPosition
            #print "maxPosition:",maxPosition
            #print outputLine
            #print doc_words[minPosition:maxPosition+1]
            tf_N_unordered_8 += 1
            
        # for N4_ordered
        if allConditionSafisfiedFlag_N4_unordered:
            #print 
            #print "in N4_unordered"
            #print indicesConditionDict_N4_unordered
            #print tempImportantPositionsList_N4_unordered
            
            minPosition = 999999
            maxPosition = 0
            outputLine = ""
            
            tempImportantPositionsList_N4_unordered.sort(cmp=None, key=None, reverse=False)
            #print tempImportantPositionsList_N4_unordered
            
            for currentTuple in tempImportantPositionsList_N4_unordered:
                (currentPosition,_) = currentTuple
                
                outputLine += doc_words[currentPosition] + " "
                
                if currentPosition < minPosition:
                    minPosition = currentPosition
                
                if currentPosition > maxPosition:
                    maxPosition = currentPosition
            #print "minPosition:",minPosition
            #print "maxPosition:",maxPosition
            #print outputLine
            #print doc_words[minPosition:maxPosition+1]
            tf_N_unordered_4 += 1
        
        # for N1_unordered
        if allConditionSafisfiedFlag_N1_unordered:
            #print 
            #print "in N1_unordered"
            #print indicesConditionDict_N1_unordered
            #print tempImportantPositionsList_N1_unordered
            
            minPosition = 999999
            maxPosition = 0
            outputLine = ""
            
            tempImportantPositionsList_N1_unordered.sort(cmp=None, key=None, reverse=False)
            #print tempImportantPositionsList_N1_unordered
            for currentTuple in tempImportantPositionsList_N1_unordered:
                (currentPosition,_) = currentTuple
                
                outputLine += doc_words[currentPosition] + " "
                
                if currentPosition < minPosition:
                    minPosition = currentPosition
                
                if currentPosition > maxPosition:
                    maxPosition = currentPosition
            #print "minPosition:",minPosition
            #print "maxPosition:",maxPosition
            #print outputLine
            #print doc_words[minPosition:maxPosition+1]
            tf_N_unordered_1 += 1            
            
                     
        # reset the judge dict
        for i in range(0,len(indicesList)):
            indicesConditionDict_N32_unordered[i] = False
        indicesConditionDict_N32_unordered[0] = True
        del tempImportantPositionsList_N32_unordered[:]
        
        # reset the judge dict
        for i in range(0,len(indicesList)):
            indicesConditionDict_N8_unordered[i] = False
        indicesConditionDict_N8_unordered[0] = True
        del tempImportantPositionsList_N8_unordered[:]
        
        # reset the judge dict
        for i in range(0,len(indicesList)):
            indicesConditionDict_N4_unordered[i] = False
        indicesConditionDict_N4_unordered[0] = True
        del tempImportantPositionsList_N4_unordered[:]
        
        # reset the judge dict
        for i in range(0,len(indicesList)):
            indicesConditionDict_N1_unordered[i] = False
        indicesConditionDict_N1_unordered[0] = True
        del tempImportantPositionsList_N1_unordered[:]
#######################################################N computation(unordered part) NEW version ends.

    if tf_M_32 != 0:
        df_dict_in_function["df_M_32"] += 1
        
    if tf_M_8 != 0:
        df_dict_in_function["df_M_8"] += 1
        
    if tf_M_4 != 0:
        df_dict_in_function["df_M_4"] += 1
        
    if tf_M_1 != 0:
        df_dict_in_function["df_M_1"] += 1

    # N ordered situation
    if tf_N_ordered_32 != 0:
        df_dict_in_function["df_N_ordered_32"] += 1
        
    if tf_N_ordered_8 != 0:
        df_dict_in_function["df_N_ordered_8"] += 1
        
    if tf_N_ordered_4 != 0:
        df_dict_in_function["df_N_ordered_4"] += 1
        
    if tf_N_ordered_1 != 0:
        df_dict_in_function["df_N_ordered_1"] += 1

    # N unordered situation
    if tf_N_unordered_32 != 0:
        df_dict_in_function["df_N_unordered_32"] += 1
        
    if tf_N_unordered_8 != 0:
        df_dict_in_function["df_N_unordered_8"] += 1
        
    if tf_N_unordered_4 != 0:
        df_dict_in_function["df_N_unordered_4"] += 1
        
    if tf_N_unordered_1 != 0:
        df_dict_in_function["df_N_unordered_1"] += 1
            
    # debug    
    # print "tf_M_32:",tf_M_32
    # print "tf_M_8:",tf_M_8
    # print "tf_M_4:",tf_M_4
    # print "tf_M_1:",tf_M_1
    
    cf_dict_in_function["cf_M_32"] += tf_M_32
    cf_dict_in_function["cf_M_8"] += tf_M_8
    cf_dict_in_function["cf_M_4"] += tf_M_4
    cf_dict_in_function["cf_M_1"] += tf_M_1

    # N ordered situation
    cf_dict_in_function["cf_N_ordered_32"] += tf_N_ordered_32
    cf_dict_in_function["cf_N_ordered_8"] += tf_N_ordered_8
    cf_dict_in_function["cf_N_ordered_4"] += tf_N_ordered_4
    cf_dict_in_function["cf_N_ordered_1"] += tf_N_ordered_1 
    
    # N unordered situation
    cf_dict_in_function["cf_N_unordered_32"] += tf_N_unordered_32
    cf_dict_in_function["cf_N_unordered_8"] += tf_N_unordered_8
    cf_dict_in_function["cf_N_unordered_4"] += tf_N_unordered_4
    cf_dict_in_function["cf_N_unordered_1"] += tf_N_unordered_1        
    
    # old version. 2012/10/19
    # outputFileHandlerForTf_dict.write(queryID + " " + trecID + " " + str(queryVariationID) + " " + queryVariationString + " "+ str(tf_M_1) + " " + str(tf_M_4) + " " + str(tf_M_8) + " " + str(tf_M_32) + " "+ str(tf_N_ordered_1) + " " + str(tf_N_ordered_4) + " " + str(tf_N_ordered_8) + " " + str(tf_N_ordered_32) + "\n")
    
    # new version.
    if tf_M_1 == 0 and tf_M_4 == 0 and tf_M_8 == 0 and tf_M_32 == 0 and tf_N_ordered_1 == 0 and tf_N_ordered_4 == 0 and tf_N_ordered_8 ==0 and tf_N_ordered_32 == 0 and tf_N_unordered_1 == 0 and tf_N_unordered_4 == 0 and tf_N_unordered_8 == 0 and tf_N_unordered_32 == 0:
        pass
    else:
        outputFileHandlerForTf_dict.write(str(queryVariationID) + " " + trecID +  " " + str(tf_M_1) + " " + str(tf_M_4) + " " + str(tf_M_8) + " " + str(tf_M_32) + " "+ str(tf_N_ordered_1) + " " + str(tf_N_ordered_4) + " " + str(tf_N_ordered_8) + " " + str(tf_N_ordered_32) + " "+ str(tf_N_unordered_1) + " " + str(tf_N_unordered_4) + " " + str(tf_N_unordered_8) + " " + str(tf_N_unordered_32)+ "\n")
    
    #print "        ","tf_M_1:",tf_M_1,"tf_M_4:",tf_M_4,"tf_M_8:",tf_M_8,"tf_M_32:",tf_M_32,"tf_N_ordered_1:",tf_N_ordered_1,"tf_N_ordered_4:",tf_N_ordered_4,"tf_N_ordered_8:",tf_N_ordered_8,"tf_N_ordered_32:",tf_N_ordered_32


#testString = "/data5/team/weijiang/the_new_trip_of_feature_generation/assignment/final-all_human_judged_webpage_paths_part_9999"

if len(sys.argv) != 2:
    print "    Usage:python programName inputPath"
    exit(1)

auxAllWebPagesPathsFileName = sys.argv[1]
partNumberInString = auxAllWebPagesPathsFileName.strip().split("_")[-1]
partNumber = int(partNumberInString)
#print "partNumber:",partNumber

print "main program begins,updated by Wei:2012/10/19"
print "change the N to N order(1,4,8,32) and N unordered(1,4,8,32) --- DONE"
print "improve the N alg to generate more OK results --- DONE"
print "optimization of the program --- DONE"
print "sort the file list --- DONE"
print "sort the output dict list --- DONE"
print "if the record has nothing(default,all the value is 0, just don't print for the tf_dicts) --- DONE"
print "perform a serious check on the results produced -- DONE"
print "write a multi-threaded or multi-process program to accelerate this process --DONE"
print "a program to caculate the final scores for each query --ongoing"







# step1
queryVariationTupleList = []
# step1: read the query variations
inputFileName = "/data5/team/weijiang/the_new_trip_of_feature_generation/final-150Clueweb09Queries-variations.txt"
inputFileHandler = open(inputFileName,"r")
for line in inputFileHandler.readlines():
    # print line
    lineElements = line.strip().split(" ")
    
    queryID = lineElements[0].split("_")[0]
    attr = lineElements[0].split("_")[1]
    queryVariations = lineElements[1:]
    
    # print "queryID:",queryID
    # print "attr:",attr
    # print "queryVariations:",queryVariations
    
    queryVariationTuple = (queryID,attr,queryVariations)
    queryVariationTupleList.append(queryVariationTuple)
inputFileHandler.close()
print "# of queries:",len(queryVariationTupleList)

cf_dicts = {}
df_dicts = {}

# give each variant an ID and output to the disk
tempNumOfVariations = 0
#tempOutputFileName = "/data5/team/weijiang/the_new_trip_of_feature_generation/final-150Clueweb09Queries-variations-only.txt"
#tempOutputFileHandler = open(tempOutputFileName,"w")

tempDuplicatedVariant = 0
for queryVariationTuple in queryVariationTupleList:
    (queryID,attr,queryVariations) = queryVariationTuple
    
    # step0: verify that this currentVariant has NOT been appeared before
    for currentVariant in queryVariations:
        if currentVariant not in cf_dicts and currentVariant not in df_dicts:
            
            #tempOutputFileHandler.write(str(tempNumOfVariations) + ":" + currentVariant + "\n")
            tempNumOfVariations += 1
            
            # create the corresponding dict
            current_cf_dict = {}
            current_cf_dict["cf_M_1"] = 0
            current_cf_dict["cf_M_4"] = 0
            current_cf_dict["cf_M_8"] = 0
            current_cf_dict["cf_M_32"] = 0
            
            current_cf_dict["cf_N_ordered_1"] = 0
            current_cf_dict["cf_N_ordered_4"] = 0
            current_cf_dict["cf_N_ordered_8"] = 0
            current_cf_dict["cf_N_ordered_32"] = 0
    
            current_cf_dict["cf_N_unordered_1"] = 0
            current_cf_dict["cf_N_unordered_4"] = 0
            current_cf_dict["cf_N_unordered_8"] = 0
            current_cf_dict["cf_N_unordered_32"] = 0
                    
            current_df_dict = {}
            current_df_dict["df_M_1"] = 0
            current_df_dict["df_M_4"] = 0
            current_df_dict["df_M_8"] = 0
            current_df_dict["df_M_32"] = 0
            
            current_df_dict["df_N_ordered_1"] = 0
            current_df_dict["df_N_ordered_4"] = 0
            current_df_dict["df_N_ordered_8"] = 0
            current_df_dict["df_N_ordered_32"] = 0
            
            current_df_dict["df_N_unordered_1"] = 0
            current_df_dict["df_N_unordered_4"] = 0
            current_df_dict["df_N_unordered_8"] = 0
            current_df_dict["df_N_unordered_32"] = 0 

            # assign the new dict into the mother dicts
            cf_dicts[currentVariant] = current_cf_dict
            df_dicts[currentVariant] = current_df_dict
        else:
            tempDuplicatedVariant += 1
            # print "Pass duplcaited variant:",tempDuplicatedVariant,currentVariant
            pass
print "num of duplcaited variant:",tempDuplicatedVariant
print "num of unique variations:",tempNumOfVariations
#tempOutputFileHandler.close()


# load back the variations and the variationID:

queryVarianceList = []
tempInputFileName = "/data5/team/weijiang/the_new_trip_of_feature_generation/final-150Clueweb09Queries-variations-only.txt"
tempInputFileHandler = open(tempInputFileName,"r")
for line in tempInputFileHandler.readlines():
    queryVarianceID = line.strip().split(":")[0]
    queryVarianceContent = line.strip().split(":")[1]
    queryVarianceTuple = (queryVarianceID,queryVarianceContent)
    queryVarianceList.append(queryVarianceTuple)
tempInputFileHandler.close()

print "len(queryVarianceList):",len(queryVarianceList)

outputFileNameForTf_dict = "/data5/team/weijiang/the_new_trip_of_feature_generation/assignment/results/final-complexFeaturesSupportedFileBothModeForTf_dicts.txt" + "_part_%2d" % partNumber
outputFileHandlerForTf_dict = open(outputFileNameForTf_dict,"w")
outputFileHandlerForTf_dict.write("queryVariationID" + " " + "trecID" + " " + "tf_M_1" + " " + "tf_M_4" + " " + "tf_M_8" + " " + "tf_M_32" + " " + "tf_N_ordered_1" + " " + "tf_N_ordered_4" + " " + "tf_N_ordered_8" + " " + "tf_N_ordered_32" + " " + " " + "tf_N_unordered_1" + " " + "tf_N_unordered_4" + " " + "tf_N_unordered_8" + " " + "tf_N_unordered_32" + "\n")

outputFileNameForCf_dicts = "/data5/team/weijiang/the_new_trip_of_feature_generation/final-complexFeaturesSupportedFileDebugForCf_dicts.txt"
outputFileHandlerForCf_dicts = open(outputFileNameForCf_dicts,"w")
outputFileHandlerForCf_dicts.write("queryVarianceID" + " " + "queryVarianceContent" + " " + "cf_M_1" + " " + "cf_M_4" + " " + "cf_M_8" + " " + "cf_M_32" + " " + "cf_N_ordered_1" + " " + "cf_N_ordered_4" + " " + "cf_N_ordered_8" + " " + "cf_N_ordered_32" + "cf_N_unordered_1" + " " + "cf_N_unordered_4" + " " + "cf_N_unordered_8" + " " + "cf_N_unordered_32"+ "\n")

outputFileNameForDf_dicts = "/data5/team/weijiang/the_new_trip_of_feature_generation/final-complexFeaturesSupportedFileDebugForDf_dicts.txt"
outputFileHandlerForDf_dicts = open(outputFileNameForDf_dicts,"w")
outputFileHandlerForDf_dicts.write("queryVarianceID" + " " + "queryVarianceContent" + " " + "df_M_1" + " " + "df_M_4" + " " + "df_M_8" + " " + "df_M_32" + " " + "df_N_ordered_1" + " " + "df_N_ordered_4" + " " + "df_N_ordered_8" + " " + "df_N_ordered_32" + "df_N_unordered_1" + " " + "df_N_unordered_4" + " " + "df_N_unordered_8" + " " + "df_N_unordered_32"+ "\n")


# divided into 2 modes: production mode and debug mode
productionMode = False

if productionMode:
    print "in production mode"
    # step2: read the document, compute and output
    
    auxAllWebPagesPathsFileHandler = open(auxAllWebPagesPathsFileName,"r")
    
    for index,currentLine in enumerate( auxAllWebPagesPathsFileHandler.readlines() ):
        filename = currentLine.strip().split("/")[-1]
        trecID = filename.split("_")[0]
        absolutePathForWebPageFileName = currentLine.strip()
        
        print "--->",index,absolutePathForWebPageFileName
        
        
        #################################################production begins...    
        documentFileHandler = open(absolutePathForWebPageFileName,"r")
        doc_content = documentFileHandler.read()
        doc_words = doc_content.strip().split(" ")
    
        for tempTestTuple in queryVarianceList:
            (queryVarianceID,queryVarianceContent) = tempTestTuple
            computeComplexFeaturesSupportedData(doc_words,queryVarianceID,queryVarianceContent,outputFileHandlerForTf_dict,cf_dicts[queryVarianceContent],df_dicts[queryVarianceContent],trecID)
        

        # finally, dump the cf_dicts and df_dicts into the disk and store as a file
        outputFileNameProductionForCf_dict = "/data5/team/weijiang/the_new_trip_of_feature_generation/assignment/results/final-complexFeaturesSupportedFileProductionForCf_dicts.txt"  + "_part_%2d" % partNumber
        outputFileHandlerProductionForCf_dicts = open(outputFileNameProductionForCf_dict,"w")
        outputFileHandlerProductionForCf_dicts.write("queryVarianceID" + " " + "queryVarianceContent" + " " + "cf_M_1" + " " + "cf_M_4" + " " + "cf_M_8" + " " + "cf_M_32" + " " + "cf_N_ordered_1" + " " + "cf_N_ordered_4" + " " + "cf_N_ordered_8" + " " + "cf_N_ordered_32" + "cf_N_unordered_1" + " " + "cf_N_unordered_4" + " " + "cf_N_unordered_8" + " " + "cf_N_unordered_32"+ "\n")

        for queryVarianceTuple in queryVarianceList:
            (queryVarianceID,queryVarianceContent) = queryVarianceTuple
            outputFileHandlerProductionForCf_dicts.write(str(queryVarianceID) + " " + queryVarianceContent + " " + str(cf_dicts[queryVarianceContent]["cf_M_1"]) + " " + str(cf_dicts[queryVarianceContent]["cf_M_4"]) + " " + str(cf_dicts[queryVarianceContent]["cf_M_8"]) + " " + str(cf_dicts[queryVarianceContent]["cf_M_32"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_ordered_1"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_ordered_4"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_ordered_8"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_ordered_32"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_unordered_1"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_unordered_4"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_unordered_8"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_unordered_32"]) + "\n")
        outputFileHandlerProductionForCf_dicts.close()
        
        outputFileNameProductionForDf_dict = "/data5/team/weijiang/the_new_trip_of_feature_generation/assignment/results/final-complexFeaturesSupportedFileProductionForDf_dicts.txt"  + "_part_%2d" % partNumber
        outputFileHandlerProductionForDf_dicts = open(outputFileNameProductionForDf_dict,"w")
        outputFileHandlerProductionForDf_dicts.write("queryVarianceID" + " " + "queryVarianceContent" + " " + "df_M_1" + " " + "df_M_4" + " " + "df_M_8" + " " + "df_M_32" + " " + "df_N_ordered_1" + " " + "df_N_ordered_4" + " " + "df_N_ordered_8" + " " + "df_N_ordered_32" + "df_N_unordered_1" + " " + "df_N_unordered_4" + " " + "df_N_unordered_8" + " " + "df_N_unordered_32"+ "\n")
        for queryVarianceTuple in queryVarianceList:
            (queryVarianceID,queryVarianceContent) = queryVarianceTuple
            outputFileHandlerProductionForDf_dicts.write(str(queryVarianceID) + " " + queryVarianceContent + " " + str(df_dicts[queryVarianceContent]["df_M_1"]) + " " + str(df_dicts[queryVarianceContent]["df_M_4"]) + " " + str(df_dicts[queryVarianceContent]["df_M_8"]) + " " + str(df_dicts[queryVarianceContent]["df_M_32"]) + " " + str(df_dicts[queryVarianceContent]["df_N_ordered_1"]) + " " + str(df_dicts[queryVarianceContent]["df_N_ordered_4"]) + " " + str(df_dicts[queryVarianceContent]["df_N_ordered_8"]) + " " + str(df_dicts[queryVarianceContent]["df_N_ordered_32"]) + " " + str(df_dicts[queryVarianceContent]["df_N_unordered_1"]) + " " + str(df_dicts[queryVarianceContent]["df_N_unordered_4"]) + " " + str(df_dicts[queryVarianceContent]["df_N_unordered_8"]) + " " + str(df_dicts[queryVarianceContent]["df_N_unordered_32"]) + "\n")
        outputFileHandlerProductionForDf_dicts.close()
        #################################################production ends.
        

else:
    print "in debug mode"
    #################################################debug begins...
    debugDocumentList = []
    # debug use document1
    absolutePathForWebPageFileName = "/data4/team/weijiang/testDir/testWebPage"
    
    trecID = "clueweb09-entest-15-17511"
    tempDebugDocumentTuple = (trecID,absolutePathForWebPageFileName)
    debugDocumentList.append(tempDebugDocumentTuple)
    
    
    # debug use document2
    absolutePathForWebPageFileName = "/data4/team/weijiang/human_judge_web_pages_plain_text_only_words/en0005/clueweb09-en0005-76-03988_17952_plain_text.txt"
    
    trecID = "clueweb09-en0005-76-03988"
    tempDebugDocumentTuple = (trecID,absolutePathForWebPageFileName)
    debugDocumentList.append(tempDebugDocumentTuple)        
    
    
    for index,tempDebugDocumentTuple in enumerate(debugDocumentList):
        (trecID,absolutePathForWebPageFileName) = tempDebugDocumentTuple
        print "--->",index,absolutePathForWebPageFileName
        documentFileHandler = open(absolutePathForWebPageFileName,"r")
        doc_content = documentFileHandler.read()
        doc_words = doc_content.strip().split(" ")
    
        # debug
        # debugVarianceList = [(0,"obama_family"),(1,"obama_tree"),(2,"family_tree"),(3,"obama_family_tree")]
        debugVarianceList = [(0,"obama_family"),(1,"obama_tree"),(2,"family_tree"),(3,"obama_family_tree"),(4,"french_lick")]
        for tempTestTuple in debugVarianceList:
            (queryVarianceID,queryVarianceContent) = tempTestTuple
            computeComplexFeaturesSupportedData(doc_words,queryVarianceID,queryVarianceContent,outputFileHandlerForTf_dict,cf_dicts[queryVarianceContent],df_dicts[queryVarianceContent],trecID)
            #print "        cf_dicts[",queryVarianceContent,"]:",cf_dicts[queryVarianceContent]
            #print "        df_dicts[",queryVarianceContent,"]:",df_dicts[queryVarianceContent]
        
        print
    
    #################################################debug ends.

# overall statistics generation
if productionMode:
    pass

else:
    # finally, dump the cf_dicts and df_dicts into the disk and store as a file  
    for queryVarianceTuple in debugVarianceList:
        (queryVarianceID,queryVarianceContent) = queryVarianceTuple
        outputFileHandlerForCf_dicts.write(str(queryVarianceID) + " " + queryVarianceContent + " " + str(cf_dicts[queryVarianceContent]["cf_M_1"]) + " " + str(cf_dicts[queryVarianceContent]["cf_M_4"]) + " " + str(cf_dicts[queryVarianceContent]["cf_M_8"]) + " " + str(cf_dicts[queryVarianceContent]["cf_M_32"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_ordered_1"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_ordered_4"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_ordered_8"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_ordered_32"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_unordered_1"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_unordered_4"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_unordered_8"]) + " " + str(cf_dicts[queryVarianceContent]["cf_N_unordered_32"]) + "\n")
    
    for queryVarianceTuple in debugVarianceList:
        (queryVarianceID,queryVarianceContent) = queryVarianceTuple
        outputFileHandlerForDf_dicts.write(str(queryVarianceID) + " " + queryVarianceContent + " " + str(df_dicts[queryVarianceContent]["df_M_1"]) + " " + str(df_dicts[queryVarianceContent]["df_M_4"]) + " " + str(df_dicts[queryVarianceContent]["df_M_8"]) + " " + str(df_dicts[queryVarianceContent]["df_M_32"]) + " " + str(df_dicts[queryVarianceContent]["df_N_ordered_1"]) + " " + str(df_dicts[queryVarianceContent]["df_N_ordered_4"]) + " " + str(df_dicts[queryVarianceContent]["df_N_ordered_8"]) + " " + str(df_dicts[queryVarianceContent]["df_N_ordered_32"]) + " " + str(df_dicts[queryVarianceContent]["df_N_unordered_1"]) + " " + str(df_dicts[queryVarianceContent]["df_N_unordered_4"]) + " " + str(df_dicts[queryVarianceContent]["df_N_unordered_8"]) + " " + str(df_dicts[queryVarianceContent]["df_N_unordered_32"]) + "\n")            

outputFileHandlerForCf_dicts.close()
outputFileHandlerForCf_dicts.close()

    
